package com.water.servlet;

import com.water.Service.Impl.WaterServiceImpl;
import com.water.Service.WaterService;
import com.water.domain.ArticleListBean;
import com.water.utils.TextUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

public class SearchServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("UTF-8");
        try {
            String title = req.getParameter("title");
            String status = req.getParameter("status");
            System.out.println(status);
            WaterService service = new WaterServiceImpl();
            List<ArticleListBean> search = service.search(title, status);
            req.setAttribute("list", search);
            if (!TextUtils.isEmpty(title)) {
                req.getRequestDispatcher("jsp/articlestemp.jsp").forward(req, resp);
            } else {
                req.getRequestDispatcher("jsp/audittemp.jsp").forward(req, resp);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
